const dbConnection = require('./db');
const express = require('express');
const app = express();

const cars = require('./router/cars');
const users = require('./router/users');
const auth = require('./router/auth');
const comments = require('./router/comments');

app.use(express.json());

// Static Folder
app.use(express.static('public'));

app.use('/api/users',users);
app.use('/api/cars',cars);
app.use('/api/auth',auth);
app.use('/api/comments',comments);

//PORT
const port = 3000;
app.listen(port,() => {
    console.log(`listening on port ${port}.....`);
});

async function dataBaseConnection(){
    try{
        app.set('db',await dbConnection());
        console.log('Database connected');
    }catch(err){
        console.err(err.message);
        process.exit(1);
    }
}

dataBaseConnection();